package cn.smile.commons.web;

import cn.smile.commons.constant.CommonConstant;
import cn.smile.utils.SpringContextUtils;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.util.ObjectUtils;

public class Header {

    /**
     * 获取 Token
     *
     * @return {@code String} token
     */
    public static String getToken() {
        HttpServletRequest request = SpringContextUtils.getHttpServletRequest();
        if (ObjectUtils.isEmpty(request)) {
            return null;
        }
        String token = request.getHeader(CommonConstant.HEADER_TOKEN_KEY);
        return ObjectUtils.isEmpty(token) ? null : token;
    }
}
